from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.conf import settings

from apps.system.models import Upload


class Media(models.Model):
    AUDIO = 1
    VIDEO = 2
    TYPE_CHOICE = (
        (AUDIO, '音频'),
        (VIDEO, '视频')
    )

    file = models.ForeignKey(Upload, verbose_name='路径', on_delete=models.PROTECT, related_name='file')
    banner = models.ForeignKey(Upload, verbose_name='封面图片', on_delete=models.PROTECT, related_name='banner')
    type = models.PositiveSmallIntegerField(choices=TYPE_CHOICE, default=AUDIO, verbose_name='媒体格式')
    user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='发表人', on_delete=models.PROTECT)
    name = models.CharField(max_length=50, verbose_name='电影名称')
    describe = models.CharField(max_length=200, verbose_name='电影描述', null=True)
    delete = models.BooleanField(verbose_name='删除', default=False)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    like_count = models.IntegerField(verbose_name='点赞', default=0)
    collect_count = models.IntegerField(verbose_name='收藏', default=0)
    browse_count = models.IntegerField(verbose_name='浏览量', default=0)

    class Meta:
        db_table = 'media'
        verbose_name = '媒体'

    @staticmethod
    def get_content_type():
        return ContentType.objects.get(model='Media'.lower())

